package com.marvels.financial.loan.service.impl;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.financial.loan.api.FinancialILoanAfterInfoApi;
import com.marvels.financial.loan.dao.McfeRepaymentFlowDao;
import com.marvels.financial.loan.dto.McfeRepaymentFlowDTO;
import com.marvels.financial.loan.service.TimeStrikeBalanceApi;

@Service
public class TimeStrikeBalanceImpl implements TimeStrikeBalanceApi{

	@Autowired
	private McfeRepaymentFlowDao mcfeRepaymentFlowDao;
	
	@Autowired
	private FinancialILoanAfterInfoApi loanAfterInfoApi;
	
	@Override
	public void excute() {
		String batName=UUID.randomUUID().toString().replace("-", "");
		//先将一批状态置为冲账中
		int count=mcfeRepaymentFlowDao.updateBatName(batName);
		if(count<1){
			MarvelsLogUtil.getInstance().info(">>>>>>>>>>没有需要冲账还款流水/冲销流水记录");
			return ;
		}
		//将该批次的冲账记录查询出来
		List<McfeRepaymentFlowDTO> list=mcfeRepaymentFlowDao.selectBybatName(batName);
		if(list!=null && list.size()>0){
			for(McfeRepaymentFlowDTO flowDTO:list){
				try {
					loanAfterInfoApi.StrikeBalance(flowDTO);
				} catch (Exception e) {
					MarvelsLogUtil.getInstance().error(">>>>>>>>>loanId:"+flowDTO.getLoanId()+",冲账异常:",e);
				}
			}
		}
	}

}
